package com.jt.controller;

import com.jt.dao.UserDAO;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserDAO userDAO;

    @RequestMapping("/findAll")
    public List<User> findAll(){
        return userDAO.findAll();
    }

    @RequestMapping("/login")
    public User login(String username,String password){
        return userDAO.findUserByUsernameAndPassword(username, password);
    }

    @RequestMapping("/findById")
    public User findById(int id){
        return userDAO.findUserById(id);
    }

    @RequestMapping("/update")
    public int updateUser(User user){
        return userDAO.update(user);
    }


    @RequestMapping("/add")
    public int addUser(User user){
        return userDAO.insert(user);
    }

    @RequestMapping("/delete")
    public int deleteUser(int id){
        return userDAO.delete(id);
    }

}
